package com.xianguo.datacenter.controller;



import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xianguo.datacenter.domain.CommodityType;
import com.xianguo.datacenter.domain.User;
import com.xianguo.datacenter.service.CommodityTypeService;
/**
 * 分类模块界面
 * @人员 鲜果
 *
 */
@Controller
public class CommTypeController {
	@Autowired
	@Qualifier("CommTypeService")
	private CommodityTypeService commTypeService;
	
	@RequestMapping(value="/commtype/addcommtype",method = RequestMethod.POST,produces = "application/json; charset=utf-8")
	@ResponseBody
	public String addCommtype(String name,int level,int parmen ,HttpServletRequest request,HttpSession session){
		User user = (User)session.getAttribute("user");
		CommodityType type = new CommodityType();
		type.setName(name);
		type.setLevel(level);
		type.setParmen(parmen);
		String commJSON = commTypeService.AddCommType(type, user);
		return commJSON;
	}
	
	@RequestMapping(value="/commtype/delectcommtype",method=RequestMethod.POST,produces = "application/json; charset=utf-8")
	@ResponseBody
	public String deleteCommtype(int id,HttpServletRequest request,HttpSession session){
		User user = (User)session.getAttribute("user");
		String commJSON = commTypeService.DelectCommType(id, user);
		return commJSON;
	}
	@RequestMapping(value="/commtype/getcommtypeBysuper",method=RequestMethod.GET,produces = "application/json; charset=utf-8")
	@ResponseBody
	public String findCommTypeBysuper(int parmen,HttpServletRequest request,HttpSession session){
		User user = (User)session.getAttribute("user");
		String commJSON = commTypeService.FindCommTypeBySuper(parmen, user);
		return commJSON;
	}
	@RequestMapping(value="/commtype/getcommtype",method=RequestMethod.GET,produces = "application/json; charset=utf-8")
	@ResponseBody
	public String findCommTypeByuid(HttpSession session){
		User user = (User)session.getAttribute("user");
		String commJSON = commTypeService.FindCommTypeByUid(user);
		return commJSON;
	}
	
	@RequestMapping(value="/commtype/updatacomm",method=RequestMethod.POST,produces = "application/json; charset=utf-8")
	@ResponseBody
	public String updataComm(int id,String name,HttpServletRequest request,HttpSession session){
		User user = (User)session.getAttribute("user");
		String commJSON = commTypeService.UpdateTypeName(id, user, name);
		return commJSON;
	}
	
	@RequestMapping(value="/commtype/selectone",method=RequestMethod.GET,produces = "application/json; charset=utf-8")
	@ResponseBody
	public String selectlevelone(HttpSession session){
		User user = (User)session.getAttribute("user");
		String commJSON = commTypeService.selectone(user);
		return commJSON;
	}
}
